package constant.milk.cashbook.tip;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import constant.milk.cashbook.R;
import constant.milk.cashbook.SuperActivity;
import constant.milk.cashbook.util.MilkTextView;

public class TipActivity extends SuperActivity
{
	private ListView listView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.tip_activity);
		
		setGoneTipButton();
		
		setTitle("도움말목록");
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		listView = (ListView) findViewById(R.id.listView);
	}

	@Override
	protected void setOnClick()
	{
	}

	@Override
	protected void setData()
	{
		ArrayList<String> list = new ArrayList<String>();
		
		list.add("메인화면");
		list.add("입력");
		list.add("조회");
		list.add("자산");
		list.add("데이터");
		list.add("카테고리");
		list.add("자동화");
		list.add("예산/통계");
		list.add("위젯");
		list.add("내 집 설정");
		
		listView.setOnItemClickListener(onItemClickListener);
		
		TipListAdapter adapter = new TipListAdapter(
				superContext, R.layout.normal_list_item, list);
		listView.setAdapter(adapter);
	}
	
	private OnItemClickListener onItemClickListener = new OnItemClickListener()
	{
		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int position,
				long arg3)
		{
			if (position == 0)
			{
				Intent intent = new Intent(superContext, TipInfoActivity.class);
				intent.putExtra(TipInfoActivity.TIP_ID, TipMap.TIP_MAIN);
				startActivity(intent);
			}
			else if (position == arg0.getCount() -1)
			{
				Intent intent = new Intent(superContext, TipInfoActivity.class);
				intent.putExtra(TipInfoActivity.TIP_ID, TipMap.TIP_MY_HOUSE);
				startActivity(intent);
			}
			else
			{
				Intent intent = new Intent(superContext, TipListActivity.class);
				intent.putExtra(TipListActivity.TIP_LIST_ID, position);
				startActivity(intent);
			}
		}
	};
	
	/**
	 * 현금 리스트 아답터
	 */
	private class TipListAdapter extends ArrayAdapter<String> 
	{
		public TipListAdapter(Context context, int textViewResourceId, ArrayList<String> list) 
		{
			super(context, textViewResourceId, list);
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent) 
		{
			View v = convertView;
			
			if (v == null) 
			{
				LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				v = inflater.inflate(R.layout.normal_list_item, null);
			}
			
			String data = getItem(position);
			
			MilkTextView nameTextView = (MilkTextView) v.findViewById(R.id.normalItemNameTextView);
			
			nameTextView.setTextSize(TEXT_SIZE);
			nameTextView.setText(data);
			
			return v;
		}
	}

	@Override
	protected void tipButton()
	{
	}

}
